<?php
/**
 * Created by PhpStorm.
 * User: jiayanxiu
 * Date: 15/10/16
 * Time: 12:06
 */
class adApp extends MallbaseApp {

    /**
     * 开机页广告信息
     * @author jyx
     * @date 2015/10/16
     */
    public function index() {
        $info = $data = array();
        $model = m('goods');
        $time = time();
        //查询出来适合app的广告活动的数量
        $sql = "SELECT COUNT(id) AS `count` FROM ".DB_PREFIX."ad WHERE start_time <= {$time} AND end_time >= {$time}
                AND  status=1 AND `position` = 4 ORDER BY id DESC";
        $info = $model->getRow($sql);
        if ($info) {
            //查询出其中的一条广告活动
            $offset = mt_rand(0, $info['count'] - 1);
            $sql = "SELECT id,`name`,img,url FROM ".DB_PREFIX."ad WHERE start_time <= {$time} AND end_time >= {$time}
                    AND  status=1 AND `position` = 4 LIMIT {$offset}, 1";
            $tmp = $model->getRow($sql);
            if ($tmp) {
                $tmp['img'] = $tmp['img'] ? QINIU_URL.$tmp['img'].'_1242_2208_2_85.jpg' : '';
                $uri = getUrlByEnv("index.php?c=activity");
                $tmp['flag'] = (strpos($tmp['url'], $uri) === false) ? 0 : 1;//如果是1表示是h5页面
                $data = $tmp;
            }
        }
        $this->ajax_return(FLAG_OK, '', $data);
    }






}